package main

import (
	"context"
	"fmt"
	_ "github.com/mbobakov/grpc-consul-resolver"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
	"mock/grpclb_test/proto"
)

func main() {
	conn, err := grpc.Dial(
		"consul://10.26.10.121:8500/user-srv?wait=14s&tag=imooc",
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy": "round_robin"}`),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	//for i := 0; i < 5; i++ {
	client := proto.NewUserClient(conn)
	list, err := client.GetUserList(context.Background(), &proto.PageInfo{
		Pn:    1,
		PSize: 5,
	})
	if err != nil {
		panic(err)
	}
	for k, v := range list.Data {
		fmt.Println(k, v)
	}
	//}
}
